//package cn.wolfcode.myinterceptor;
//
//import cn.wolfcode.domain.Result;
//import cn.wolfcode.util.JwtUtils;
//import com.alibaba.fastjson.JSONObject;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//import org.springframework.util.StringUtils;
//import org.springframework.web.servlet.HandlerInterceptor;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//@Slf4j
//@Component
//public class LoginCheckInterceptor implements HandlerInterceptor {
//    //目标资源方法之前执行  HandlerMapping 之后  HandlerAdapter 之前
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        System.out.println("prehandle......");
//        /**
//         * 获取Token 如果没有  就驳回
//         * 如果有 1 可以解析 方向
//         *       2 解析失败 驳回
//         */
//        String token=request.getHeader("token");
//        if(StringUtils.isEmpty(token)){
//            log.info("Token不存在");
//            response.setContentType("application/json;charset=utf-8");
//            response.getWriter().write(JSONObject.toJSONString(Result.error("NOT_LOGIN")));
//            return false;
//        }
//
//        //解析Token
//        try {
//            JwtUtils.parseJWT(token);
//        } catch (Exception e){
//            e.printStackTrace();
//            log.info("Token无法解析");
//            response.setContentType("application/json;charset=utf-8");
//            response.getWriter().write(JSONObject.toJSONString(Result.error("NOT_LOGIN")));
//            return false;
//        }
//        return true;
//    }
//
////    //处理方法执行之后  执行的操作
////    @Override
////    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
////        System.out.println("postHandle.....");
////    }
////
////    //视图渲染完毕之后
////
////    @Override
////    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
////        System.out.println("afterCompletion....");
////    }
//}
